package cn.edu.nhic.filter;

import cn.edu.nhic.constant.Constants;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description
 * @Date 2024/9/14 14:31
 * @Created by dwp
 */

@WebFilter(urlPatterns = "/*")
public class CharacterFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;


        request.setCharacterEncoding(Constants.CharSetEnum.UTF_8.getCharSet());
        response.setContentType(Constants.DOC_FORMAT_TYPE);

        CharacterServletRequest req = new CharacterServletRequest(request);

        filterChain.doFilter(req, response);
    }

    @Override
    public void destroy() {

    }
}
